import { effect } from "./effect.js";
import { reactive } from "./reactive.js";
import { ref } from "./ref.js";
import { computed } from "./computed.js";

const num = ref(0);
effect(() => {
  console.log(num.value);
});
// num.value++
// console.log(num)
const obj2 = reactive({
  a: 1,
  b: 3,
});
const sum = computed(() => {
  console.log("computed",obj2.a + obj2.b);
  return obj2.a + obj2.b;
});
effect(() => {
  console.log(sum.value);
})
console.log(sum.value);
const obj = {
  name: "张三",
  age: 0,
  info: {
    height: 1.88,
    weight: 75,
  },
  get fullName() {
    console.log(this);
    return this.name + "-" + this.age;
  },
};
// const state = reactive(obj);
// state.c=890;
// function fn() {
//   state.age
//   state.name
//  // state.age = 10;
// }

//effect(fn)
// function fn1() {
//   console.log('fn1')
//   state.c=20
//   state.info
//  // state.age = 10;
//  for(const key in state){
//  }
// }

// state.c=890;
//effect(fn1)

// for (const key in obj) {
//   console.log(key);
// }

// let _array=[1,2,3,4,5,6,7,8,9,obj,10];
// let _array2=reactive(_array);
//console.log(_array2.length);
//_array2.push(65)
//var i=_array2.includes(obj);
//  _array2[16]=90;
// _array2.length=3;
// console.log(_array2);
//_array2.length=20;
//console.log(i);
//console.log(state.age);
//delete state.name;
//delete state.dds;
//state.age = -10;
//state.name = "李四";
//state.bbc=1;
// console.log(state);
function fnm() {
  //state.name = '李四'
  //state.info.height
  //   state.fullName;
  //   "d" in state;
  //   for (const key in state) {
  //     console.log(key);
  //   }
  //Object.keys(state);
}

// fn();
// const arr = [1, 2, 3, 4, 5];
// const _arr=reactive(arr);
// for (const item of _arr) {
//   item;
// }

const target = { name: "Alice" };
const proxy = new Proxy(target, {
  get(target, prop) {
    console.log(`Getting ${prop}`);
    return target[prop];
  },
  set(target, prop, value) {
    console.log(`Setting ${prop}`, target[prop], value);
    target[prop] = value;
    return true;
  },
});
//console.log(proxy)
//proxy.name = 'Bob'; // 输出: Setting name
//console.log(proxy.name); // 输出: Getting name; Bob
